package com.inspur.controller;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.inspur.pojo.RegularMeet;
import com.inspur.pojo.RegularMeetWork;
import com.inspur.pojo.RegularWorkExt;
import com.inspur.service.RegularWorkService;
import com.sun.net.httpserver.Filter.Chain;


@Controller
public class RegularWorkController {
	@Autowired
	private RegularWorkService regularWorkService;
	
	@RequestMapping(value = "/regularMeetingWork")
	public String getRegularWorkList(Model model,
			@RequestParam(value = "pn", defaultValue = "1") Integer pn,
			HttpServletRequest request) {
		String mgrId=request.getParameter("mgrId");
		String date=request.getParameter("date");
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("mgrId", mgrId);
		map.put("date", date);
		PageHelper.startPage(pn, 3);
		List<RegularWorkExt> meetList = null;
	
		// 调用Service层

		meetList = regularWorkService.getWorkList(map);
	
		PageInfo<RegularWorkExt> pageInfo = new PageInfo<RegularWorkExt>(meetList,meetList.size());

		System.out.println("工作的条数：" + meetList.size());
		model.addAttribute("pageInfo", pageInfo);

		return "/manager/regularMeetingWork.jsp";
	}
	
	@RequestMapping("/regularWorkingAdd")
	public String addRegularWorking(RegularMeetWork regularMeetWork, Model model) {
		
	  regularWorkService.addRegularWorking(regularMeetWork);
		model.addAttribute("saveFlag", "1");
		model.addAttribute("meet", regularMeetWork);
		model.addAttribute("message", "保存成功");
		return "/manager/regularWorkingAdd.jsp";
	}
	
	@RequestMapping("/deletework")
	public String deletework(String cmkeys){
		String cmkey[] = cmkeys.split(",");
		int meet_cmkeys[] = new int[cmkey.length];
		for(int i=0;i<cmkey.length;i++){
			meet_cmkeys[i] = Integer.parseInt(cmkey[i]);
		}
		regularWorkService.deletework(meet_cmkeys);
		
		//删除数据后要重新查询一次
		return "redirect:regularMeetingWork";
	}
	
	@RequestMapping("/modifyworking")
	public String modifyworking(String cmkey,Model model){
	  int meet_key = Integer.parseInt(cmkey);
	  RegularMeetWork meet = regularWorkService.getMeetbycmkey(meet_key);
	  model.addAttribute("meet", meet);
	  return "/manager/regularWorkingUpdate.jsp";
	}
	@RequestMapping("/regularWorkingUpdate")
	 public String regularMeetingUpdate(RegularMeetWork regularMeetWork,Model model) {
	
		
		regularWorkService.regularWorkingUpdate(regularMeetWork);
		model.addAttribute("saveFlag", "1");
		model.addAttribute("meet", regularMeetWork);
		model.addAttribute("message", "修改成功");
		return "/manager/regularWorkingUpdate.jsp";
	}
}
